package com.dd.census.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.dd.census.entity.Images;
import com.dd.census.mapper.ImagesMapper;
import com.dd.census.service.ImagesService;

/**
 * 业务层实现类
 * ImagesServiceImpl
 * @author whn
 * @date 2020/11/20
 */
@Service
public class ImagesServiceImpl implements ImagesService {

    @Autowired
	ImagesMapper mapper;

    @Override
    public int insert(Images images) {
        return mapper.insert(images);
    }

    @Override
    public int batchInsert(List<Images> list) {
    	return mapper.batchInsert(list);
    }

    @Override
    public int update(Images images) {
    	return mapper.update(images);
    }

    @Override
    public int delete(Images images) {
    	return mapper.delete(images);
    }

    @Override
    public int batchDelete(List<Images> list) {
        return mapper.batchDelete(list);
    }

	@Override
	public Images selectByKey(Images key) {
		return mapper.selectByKey(key);
	}

	@Override
	public List<Images> selectList(Images images) {
		return mapper.selectList(images);
	}

	@Override
	public Map<String, Object> selectPage(Images images) {
		Map<String, Object> map = new HashMap<String, Object>();

		int total = this.total(images);
		
		map.put("pageCount", Math.ceil((double) total / images.getPageSize()));// 总页数
		map.put("total", total);// 总条数
		map.put("index", images.getPageIndex());// 当前页

		if (total > 0) {
			images.setPageIndex(images.getPageSize() * (images.getPageIndex() - 1));
			map.put("items", mapper.selectPage(images));
		}

		return map;
	}

	@Override
	public int total(Images images) {
		return mapper.total(images);
	}
}